<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm">
							<div class="form-group">	
								<label class="col-sm-3 control-label">寄出日期：</label>
								<div class="col-sm-5">
									<div class="input-group date" id='date1' >
										<input id="mailDate" name="mailDate" type="text" class="form-control">
										<span class="input-group-addon">
												<i class="glyphicon glyphicon-calendar"></i>
											</span>
									</div>
								</div>

							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">单号：</label>
								<div class="col-sm-8">
									<input id="mailSn" name="mailSn" class="form-control" type="text">
								</div>
							</div>
														<div class="form-group">	
								<label class="col-sm-3 control-label">所寄物品：</label>
								<div class="col-sm-8">
									<input id="mailObj" name="mailObj" class="form-control" type="text">
								</div>
							</div>
														<div class="form-group">	
								<label class="col-sm-3 control-label">收件人：</label>
								<div class="col-sm-8">
									<input id="reciever" name="reciever" class="form-control" type="text">
								</div>
							</div>
														<div class="form-group">	
								<label class="col-sm-3 control-label">地址：</label>
								<div class="col-sm-8">
									<input id="address" name="address" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">电话：</label>
								<div class="col-sm-8">
									<input id="phone" name="phone" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">完整地址：</label>
								<div class="col-sm-8">
									<textarea id="totalAdd" style="width:100%;" name="totalAdd" rows="4"></textarea>
								</div>

							</div>
							<div class="form-group">

								<button type="button" onclick="analyze()" class="btn btn-default" style="float: right;margin-right: 150px;">智能识别</button>

							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">软著名称：</label>
								<div class="col-sm-8">
									<textarea id="copyrightSn" style="width:100%;" name="copyrightSn" th:text="${copyrightSn}" rows="12"></textarea>
								</div>
								<input id="sns" name="sns" class="form-control" type="hidden" th:value="${sns}">

							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button type="submit" class="btn btn-primary">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
	</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" src="/js/appjs/biz/maillist/add.js">
	</script>
	<script>
		$(function () {
			$('#date1').datetimepicker({
				format: 'YYYY-MM-DD',
				locale: moment.locale('zh-cn')
			});
		});

		function trimStr(str){
			return str.replace(/(^\s*)|(\s*$)/g,"");
		}

		function analyze() {

			var totalAdd=document.getElementById('totalAdd').value;
			if(totalAdd.length<5){
				alert("您输入的地址太短，无法识别。");
				return;
			}
			totalAdd=trimStr(totalAdd);
			var strs = new Array(); //定义一数组
			var result = new Array();
			strs = totalAdd.split(","); //字符分割
			while (strs.length<3){
				while (strs.length<2){
					strs=totalAdd.split("，");

					if(strs.length<2){
						strs=totalAdd.split("；");
					}
					if(strs.length<2){
						strs=totalAdd.split(" ");
					}
					break;
				}
				var str1=strs[0].toString();
				var str2=strs[1].toString();
				result = str1.split("，").concat(str2.split("；"));
				if(result.length<3){
					result = str1.split("；").concat(str2.split("，"));
				}
				strs=result;
			}


			for(i=0;i<strs.length;i++){
				var tempValue=strs[i].toString();
				var patt1 = /^[0-9]/;
				//tempValue.substr(0,1)=="1"
				if(tempValue.substr(0,1).match(patt1)) {
					$('#phone').val(tempValue);
					continue;
				}else if(tempValue.length < 6 && tempValue.length > 0){
					$('#reciever').val(tempValue);
					continue;
				}else if(tempValue.length >= 6 ){
					$('#address').val(tempValue);
				}
			}
	/*		$('#reciever').val(strs[0]);
			$('#address').val(strs[1]);
			$('#phone').val(strs[2]);*/
		}
	</script>
</body>
</html>
